package com.hbter630.change.config;



import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Title: CorsConfig
 * @Author 笑霸fianl
 * @Package com.hbter630.change.config
 * @Date 2023/5/24 20:46
 * @描述:
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    @Resource
    private CorsInterceptor corsInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 跨域拦截器需放在最上面
        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
        // 校验登录的拦截器
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns("/Admin/user/login")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
                .excludePathPatterns("/api/register")
                .excludePathPatterns("/api/register")
//             api/checkusername
                .excludePathPatterns("/api/alllist")
                .excludePathPatterns("/api/item/**")
                .excludePathPatterns("/api/email/**")
                .excludePathPatterns("/common/**")
                .excludePathPatterns("/api/list")
                .excludePathPatterns("/api/checkusername/**","/api/checkemail/**")
                .excludePathPatterns("/api/product/**")
                .excludePathPatterns("/api/passport/login");
    }
}

